/**
 * @description 学校信息
 */
import { defineStore } from 'pinia'
import type { SchoolInfoType } from '@/types/schoolInfo'
import { getBy } from '@/api/schoolInfoManagement'

export const useSchoolStore = defineStore('school', {
  state: (): { schoolInfo: SchoolInfoType } => ({
    schoolInfo: <SchoolInfoType>{},
  }),
  getters: {},
  actions: {
    /**
     * @description 设置学校信息
     */
    setSchoolInfo(schoolInfo: SchoolInfoType) {
      this.schoolInfo = schoolInfo
    },
    async getSchoolInfo() {
      // #ifdef H5
      const { data } = await getBy({ domain: location.hostname })
      this.setSchoolInfo(data)
      // #endif
    },
  },
})
